@extends('layouts.default') @section('main')
    <link rel="stylesheet" href="/css/uniform.css" />
    <link rel="stylesheet" href="/css/select2.css" />
    <div id="content">
        <div id="content-header">
            <div id="breadcrumb">
                <a href="{{url('home')}}" title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a>
                <a href="{{url('maker/list')}}" class="current">创客空间管理</a>
                <a href="#" class="current">成员管理</a></div>
        </div>
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span12">
                    @if(in_array('add',$actions))<a href="{{url('maker/create-member?maker_id='.$maker_id)}}"><button class="btn">新增</button></a>@endif

                    <div class="widget-box">
                        <div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>
                            <h5>创客空间成员管理</h5>
                        </div>
                        <div class="widget-content nopadding">
                            <table class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th>昵称</th>
                                    <th>用户名</th>
                                    <th>来源</th>
                                    <th>注册时间</th>
                                    <th>最后登录时间</th>
                                    <th>访问数</th>
                                    <th>用户详情</th>
                                    <th>是否管理员</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($users as $key => $user)
                                    <tr class="gradeX">
                                        <td>{{$user->nickname}}</td>
                                        <td>{{$user->username}}</td>
                                        <td>@if($user->source==0)web @elseif($user->source==1)投融1.0导入 @elseif($user->source==2)微信 @elseif($user->source==3)后台添加 @elseif($user->source==4)内部注册 @elseif($user->source==5)经纪人代发 @endif</td>
                                        <td>{{date('Y-m-d',$user->reg_time)}}</td>
                                        <td>{{date('Y-m-d',$user->last_time)}}</td>
                                        <td>{{$user->login_count}}</td>
                                        <td><a href="{{ url('user/info?uid='.$user->uid) }}">点击查看</a></td>
                                        <td>@if($user->is_leader == 1)<i class="icon-group"></i>@elseif($user->is_leader == 0)<i class="icon-user"></i>@endif</td>
                                        <td>@if($user->status == 1)<i class="icon-ok"></i>@elseif($user->status == 0)<i class="icon-ban-circle"></i>@endif</td>
                                        <td class="center">
                                            @if($user->is_leader == 0)
                                                @if(in_array('leader',$actions))<a data-original-title="设置为创始人" data-toggle="modal" class="tip set_leader"   href="#myAlert" uid="{{$user->uid}}" maker_id="{{$maker_id}}" href="{{url('maker/set-leader?uid='.$user->uid.'&maker_id='.$maker_id)}}"><i class="icon-group"></i></a>@endif
                                                @if(in_array('delete',$actions))<a data-original-title="删除" class="tip delete" data-toggle="modal" href="#delAlert"  uid="{{$user->uid}}" maker_id="{{$maker_id}}" ><i class="icon-trash"></i></a>@endif
                                            @endif
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                        <?php echo $users->appends(['id' => $maker_id])->render();?>
                </div>
            </div>
            <div>
                <div id="myAlert" class="modal hide">
                    <div class="modal-header">
                        <button data-dismiss="modal" class="close" type="button">×</button>
                        <h3>提示</h3>
                    </div>
                    <div class="modal-body">
                        <p>确定要将该名会员设置为空间管理员吗？原管理员将会自动转变为普通会员。</p>
                    </div>
                    <div class="modal-footer">
                        <a data-dismiss="modal" class="btn btn-primary" href="javascript:void(0);">确定</a>
                        <a data-dismiss="modal" class="btn" href="javascript:void(0);">取消</a>
                    </div>
                </div>
                <form action="{{url('maker/set-leader')}}" method="post"
                      id="setLeader">
                    <input type="hidden" name="maker_id" value="0">
                    <input type="hidden" name="uid" value="0">
                </form>
            </div>

            <div>
                <div id="delAlert" class="modal hide">
                    <div class="modal-header">
                        <button data-dismiss="modal" class="close" type="button">×</button>
                        <h3>提示</h3>
                    </div>
                    <div class="modal-body">
                        <p>确定要将该会员从此创客空间中移除吗？</p>
                    </div>
                    <div class="modal-footer">
                        <a data-dismiss="modal" class="btn del_btn-primary" href="javascript:void(0);">确定</a>
                        <a data-dismiss="modal" class="btn" href="javascript:void(0);">取消</a>
                    </div>
                </div>
                <form action="{{url('maker/del-member')}}" method="post"
                      id="delMember">
                    <input type="hidden" name="now_maker_id" value="0">
                    <input type="hidden" name="del_uid" value="0">
                </form>
            </div>
            @include('errors.list')
            @include('message.flash')
        </div>
    </div>
    <script src="/js/matrix.tables.js"></script>
    <script src="/js/common.js"></script>

    <script>
        $(".set_leader").click(function(){
            var uid = $(this).attr("uid");
            var maker_id = $(this).attr("maker_id");
            $("input[name='uid']").val(uid);
            $("input[name='maker_id']").val(maker_id);
        });

        $(".btn-primary").click(function(){
            var uid = $("input[name='uid']").val();
            var maker_id = $("input[name='maker_id']").val();
            if(maker_id == 0 || uid==0){
                alert('参数异常');
                return;
            }
            ajaxRequest($('#setLeader').serializeArray(),$('#setLeader').attr('action'),function(data){
                if(data.status){
                    alert(data.message);
                    window.location.href = data.forwardUrl;
                }else{
                    alert(data.message);
                }
            });
        });

        $(".delete").click(function(){
            var uid = $(this).attr("uid");
            var maker_id = $(this).attr("maker_id");
            $("input[name='del_uid']").val(uid);
            $("input[name='now_maker_id']").val(maker_id);
        });

        $(".del_btn-primary").click(function(){
            var uid = $("input[name='del_uid']").val();
            var maker_id = $("input[name='now_maker_id']").val();
            if(maker_id == 0 || uid==0){
                alert('参数异常');
                return;
            }
            ajaxRequest($('#delMember').serializeArray(),$('#delMember').attr('action'),function(data){
                if(data.status){
                    alert(data.message);
                    window.location.href = data.forwardUrl;
                }else{
                    alert(data.message);
                }
            });
        });

    </script>
@stop

